﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.Common.BLL;
using System.Data;
using System.Web.UI.DataVisualization.Charting;
using System.Drawing;

public partial class Police_Question_Analyse : System.Web.UI.Page
{
    private string[] charts = { "Column", "Spline", "StepLine", "Spline" };
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            Bind(Request["ID"]);
    }

    private void Bind(string sID)
    {

        if (!string.IsNullOrEmpty(sID))
        {
            DataView dv = SplitPage.ExecuteSQL("Select Left(DepartmentID,4) as DepartmentID,aliasName,(Select Sum(case when Score is null  then 0 else Score end)/case when(  (Select max(mark) From SecurityEvaluate..SecurityOption2 where pid ='" + new Guid(Request["ID"]) + "') *SecurityEvaluate.dbo.GetDepartmentIDCountt2D(Left(DepartmentID,4),'" + Request["ID"] + "'))=0 then 1 else (  (Select max(mark) From SecurityEvaluate..SecurityOption2 where pid ='" + new Guid(Request["ID"]) + "') *SecurityEvaluate.dbo.GetDepartmentIDCountt2D(Left(DepartmentID,4),'" + Request["ID"] + "'))  end From SecurityEvaluate..Securityresult2 Where Left(SetDepartment,4)=Left(DepartmentID,4)  And pid='" + new Guid(Request["ID"]) + "' ) as 'Score'  From FireMis..Account_Departments Where aliasName <>''  group by Left(DepartmentID,4),aliasName order by Score desc ").Tables[0].DefaultView;



            Chart1.Series["未超出警戒线单位"].Points.DataBindXY(dv, "aliasName", dv, "Score");
            for (int i = 0; i < dv.Table.Rows.Count; i++)
            {
                Chart1.Series["未超出警戒线单位"].Points[i].Url = "View.aspx?DepartmentID=" + dv.Table.Rows[i][0] + "&ID=" + Request["ID"] + "&sid="+Request["sid"];
            }

            Question2DataContext db = new Question2DataContext();
            var obj = (from o in db.SecurityProblem2 where o.Id == new Guid(Request["ID"]) select o).FirstOrDefault();

            decimal Standard = obj.GuardCount.Value;

            // add a series to the chart
            Series series = Chart1.Series.Add("警戒线");
            series.ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), charts[Chart1.Series.Count - 1], true);
            series.BorderWidth = 1;
            series.BorderColor = Color.Red;
            series.ShadowOffset = 0;
            series.Color = Color.Red;
            string Department = string.Empty;
            int j = 0;

            while (j++ < Chart1.Series["未超出警戒线单位"].Points.Count)
            {
                double temp = double.Parse(Standard.ToString());
                series.Points.Add(temp / 100);

            }
            for (int i = 0; i < dv.Table.Rows.Count - 1; i++)
            {
                if (dv.Table.Rows[i][2] == DBNull.Value)
                    break;

                if (decimal.Parse(dv.Table.Rows[i][2].ToString()) * 100 >= Standard)
                {
                    Department += dv.Table.Rows[i]["aliasName"] + "支队、";
                    Chart1.Series["未超出警戒线单位"].Points[i].Color = Color.FromArgb(200, 0, 0);
                }

            }
            if (Department != string.Empty)
            {
                Department = Department.Remove(Department.Length - 1);
                lbljinggao.Text = "<font color=red>警告：</font>" + Department + "已超出警戒线";
            }
            Chart1.ChartAreas["ChartArea1"].AxisX.IsLabelAutoFit = false;
            Chart1.Series["未超出警戒线单位"].LabelFormat = "p0";

            lblRemark.Text = "<font color=green>备注：</font>" + "如果各大中队超出警戒线柱状图将变为红色";
        }

    }
    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
        //
        // CODEGEN: This call is required by the ASP.NET Web Form Designer.
        //
        InitializeComponent();
        base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {

    }
    #endregion
    protected void Chart1_Click(object sender, ImageMapEventArgs e)
    {
        string ss=e.PostBackValue.ToString();
    }
}
